USE [cloudmusicdc]
GO
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID('WeatherAddWeatherData'))
BEGIN
    DROP PROCEDURE WeatherAddWeatherData
END

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/****** Object:  StoredProcedure [dbo].[WeatherAddWeatherData]    Script Date: 12/05/2013 23:57:20 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Tien>
-- Create date: <5/12/2013>
-- Description:	<>
-- =============================================
CREATE PROCEDURE [dbo].[WeatherAddWeatherData]
	@Id INT output,
	@Status nvarchar(max),
	@DegreeCelsius FLOAT,
	@GPSId INT
AS
DECLARE
	@intReturn      INT,
	@gId			INT
BEGIN
	SET NOCOUNT ON;
	
	SET @gId = NULL
	SELECT TOP 1
		@gId = @GPSId
	FROM dbo.[GPS]
	WHERE Id = @GPSId
	
	IF @gId IS NOT NULL BEGIN
		INSERT INTO Weather(Status, DegreeCelsius, GPSId)
		VALUES(@Status, @DegreeCelsius, @GPSId)
	END
	ELSE BEGIN
		SET @intReturn = 0
	END
	SET @Id = (SELECT SCOPE_IDENTITY())
END
